package lagou.server;

import server.model.Request;
import server.model.Response;
import server.servlet.HttpServlet;
import server.util.HttpProtocolUtil;

import java.io.IOException;

/**
 * @author swzhang
 * @version v1.0
 * @date 2021-11-19 10:47
 */
public class Demo2Servlet extends HttpServlet {
    @Override
    public void doGet(Request request, Response response) {
        String content = "<h1>Demo2Servlet get</h1>";
        try {
            response.output((HttpProtocolUtil.getHttpHeader200(content.getBytes().length) + content));
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    @Override
    public void doPost(Request request, Response response) {
        String content = "<h1>Demo2Servlet post</h1>";
        try {
            response.output((HttpProtocolUtil.getHttpHeader200(content.getBytes().length) + content));
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    @Override
    public void init() throws Exception {
        System.out.println(this.getClass().getName() + "init");
    }

    @Override
    public void destory() throws Exception {

    }

}
